package org.applet.game.framework.map;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class MapLoader {

	public static Node[][] loadMapDescription(String filePath) throws IOException
	{
		Node[][] map = null;
		BufferedReader reader = new BufferedReader(new FileReader(filePath));
		String line = reader.readLine();
		String[] info = line.split(",");
		short width = Short.parseShort(info[0]);
		short height = Short.parseShort(info[1]);
		map = new Node[height][width];
		
		for(short h=0;h<height;h++)
		{
			line = reader.readLine();
			Node[] row = map[h];
			for(short i=0;i<width;i++)
			{
				Node node = new Node();
				node.X = i;
				node.Y = h;
				node.Enabled = line.charAt(i)=='1'?true:false;
				row[i] = node;
			}
		}
		
		return map;
	}
	
	
	public static void main(String[] args) throws IOException {
		System.out.println(new File(".").getAbsolutePath());
		System.out.println(new File("ydg1.txt").exists());
		loadMapDescription("ydg1.txt");
	}

}
